package com.itheima.boottlias.controller;

import cn.hutool.core.util.ObjUtil;
import com.itheima.boottlias.domain.vo.Result;
import com.itheima.oss.AliyunOSSOperator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author ghy
 * @version 1.0
 * @since 2025-07-12 16:48
 */
@RestController
@Slf4j
public class FileController {

    @Autowired
    private AliyunOSSOperator aliyunOSSOperator;

    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws Exception {
        log.info("{}", file);
        if(ObjUtil.isNull(file) || file.getSize() == 0) {
            return Result.error("上传文件不能为空");
        }
        String path = aliyunOSSOperator.upload(file.getBytes(), file.getOriginalFilename());
        return Result.success(path);
    }

}
